<?php
if(get_theme_option('featured_posts') != '') {
?>
	<div class="featured-post-slider clearfix">
    
    <div class="featured-post-slides-container clearfix">
        
        <div class="featured-post-slides">		
            	<?php
				$featured_posts_category = get_theme_option('featured_posts_category');
				
				if($featured_posts_category != '' && $featured_posts_category != '0') {
					global $post;

					 $featured_posts = get_posts("numberposts=5&&category=$featured_posts_category");
					 $i = 0;
					 foreach($featured_posts as $post) {
					 	setup_postdata($post);
                        if ( version_compare( $wp_version, '2.9', '>=' ) ) {
                            $slide_image_full = get_the_post_thumbnail($post->ID,'large', array('class' => 'full'));
                            $slide_image_thumbnail = get_the_post_thumbnail($post->ID,'large', array('class' => 'thumbnail'));
                        } else {
                            $get_slide_image = get_post_meta($post->ID, 'featured', true);
                            $slide_image_full = "<img src=\"$get_slide_image\" class=\"full\" alt=\"\" />";
                            $slide_image_thumbnail = "<img src=\"$get_slide_image\" class=\"thumbnail\" alt=\"\" />";
                        }
					 	
					  ?>
					<div class="featured-post-slides-items">
						<div class="featured-post-thumbnail">
                 			<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="open">
								<?php echo  $slide_image_full; ?>
							</a> 
						</div>                       
						<div class="featured-post-content-wrap">
							<div class="featured-post-content">
								<h3 class="featured-post-title">
									<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
								</h3>
								<?php the_excerpt(); ?>
								<?php //echo  $slide_image_thumbnail; ?>
							</div>
						</div>
					</div>
					 <?php }
				} else {
					for($i = 1; $i <=5; $i++) {
						?>
					<div class="featured-post-slides-items">
                        <div class="featured-post-thumbnail">
                        	<a title="This is default featured slide 5 title" href="#">
								<img src="<?php bloginfo('template_directory'); ?>/jdgallery/slides/<?php echo $i; ?>.jpg" class="thumbnail" alt="" />
							</a>
						</div>
						<div class="featured-post-content-wrap">
        					<div class="featured-post-content">
                                <h3 class="featured-post-title">
									<a href="#">Это популярная запись № <?php echo $i; ?></a>
								</h3>
								<p>Чтобы задать популярную запись, пожалуйста зайдите в настройки темы в панели администратора. Также вы можете отключить данную опцию.</p>
							</div>
						</div>
					</div>
						<?php
					}
				}
				
				?>
			
		</div>
        
        
             <div class="featured-post-prev-next-wrap">
                <div class="featured-post-prev-next">
                    <a href="#featured-post-next" class="featured-post-next"></a>
                    <a href="#featured-post-prev" class="featured-post-prev"></a>
                </div>
            </div>
     
     <div class="featured-post-nav">
                <span class="featured-post-pager">&nbsp;</span>
            </div>  
        
	</div>
</div>
<script>
	$j=jQuery.noConflict();
	$j(document).ready(function(){
		jQuery('.featured-post-slides').cycle({
			fx: 'scrollHorz',
			timeout: 4000,
			delay: 0,
			speed: 400,
			next: '.featured-post-next',
			prev: '.featured-post-prev',
			pager: '.featured-post-pager',
			continuous: 0,
			sync: 1,
			pause: 1,
			pauseOnPagerHover: 1,
			cleartype: true,
			cleartypeNoBg: true,
			containerResize: 1,
			slideResize: 1,
			fit: 1
		});
		slideinit();
	 });

	 function slideinit() {
		var w = jQuery('#content').width();
		jQuery('img.thumbnail').css('width', w);
		jQuery('img.thumbnail').css('height', w/2);
		jQuery('featured-post-slides-items').css('width', w);
		jQuery('div.featured-post-thumbnail').css('height', w/2);
		jQuery('div.featured-post-slides').css('height', w/2);/*
		jQuery('img.thumbnail').each(function(index) {
			var ht = jQuery(this).width;
			var wt = jQuery(this).height;
			var prop = wt/ht;
			jQuery(this).css('width', w);
			jQuery(this).css('height', w / prop);
			
			jQuery('div.featured-post-thumbnail a').css('width', w);
			-items').css('width', w);
			jQuery('.featured-post-slides').css('height', w / prop);
			jQuery('div.featured-post-slides-container').css('width', w - 25);
			jQuery('div.featured-post-slides-container').css('height', w / prop);
		});
		jQuery('div.featured-post-content').css('width', w - 25);*/
		
		
	 }
	var globalTimer = null;
	jQuery(window).resize(function() {
		clearTimeout(globalTimer);
		globalTimer = setTimeout(slideinit, 200);
	});
</script>

<?php } ?>